package com.fuyin.service.user.impl;

import com.fuyin.commons.utils.MyUtils;
import com.fuyin.dao.ZbDao;
import com.fuyin.entity.Fxb;
import com.fuyin.service.user.ZbService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author yuanxilan (yuanxilan@keep.com)
 * @Description
 * @date 2021年11月12日 3:49 下午
 * @since
 */
@Service
@Slf4j
public class ZbServiceImpl implements ZbService {

    @Autowired
    private ZbDao zbDao;

    @Override
    public List<Fxb> getFxbByType(Integer type) {
        if (Objects.isNull(type) || type < 0 || type > 3) {
            log.error("com.fuyin.service.user.impl.ZbServiceImpl#getFxbByType type: {}", type);
            return new ArrayList<>();
        }
        return zbDao.getFxbByType(type);
    }

    @Override
    public List<Fxb> getFxbs() {
        return zbDao.getFxbs();
    }

    @Override
    public void insertFxb(Integer type, List<String> fss, List<String> fxds, List<String> jys) {
        if (Objects.isNull(type) || type < 0 || type > 3) {
            log.error("com.fuyin.service.user.impl.ZbServiceImpl#insertFxb type: {}", type);
            return;
        }
        if (fss.size() != fxds.size() || fss.size() != jys.size() || fss.size() == 0) {
            log.error("com.fuyin.service.user.impl.ZbServiceImpl#insertFxb fss: {}, fxds: {}, fss:{}", fss, fxds, fss);
        }
        for (int i = 0; i < fss.size(); ++i) {
            String fs = fss.get(i);
            String fxd = fxds.get(i);
            String jy = jys.get(i);
            MyUtils.checkParams("风险表指标不能为空", fs, fxd, jy);
            zbDao.insertFxb(type, fs, fxd, jy);
        }
    }
}
